package cn.wolfcode.luowowo.util;
import cn.wolfcode.luowowo.exception.LogicException;
import org.springframework.util.StringUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegistUtil {
    //验证参数是否填的是空
    public static void isEmpty(String value,String msg){
        String newValue = value.replace(" ", "");
        if (!StringUtils.hasLength(newValue)){
            throw new LogicException(msg);
        }
    }
    //验证两次密码是否一样
    public static void isEqual(String password, String rpassword,String msg){
        if (!password.equals(rpassword)){
            throw new LogicException(msg);
        }
    }
    //验证手机格式
    public static boolean isMobile(String str) {
        Pattern p = null;
        Matcher m = null;
        boolean isMatch = false;
        // 制定验证条件，目前有些新卡会出现类似166开头的，需要适当调整
        String regex1 = "^[1][3,4,5,7,8][0-9]{9}$";
        String regex2 = "^((13[0-9])|(14[579])|(15([0-3,5-9]))|(16[6])|(17[0135678])|(18[0-9]|19[89]))\\d{8}$";
        p = Pattern.compile(regex2);
        m = p.matcher(str);
        isMatch = m.matches();
        return isMatch;
    }
}
